
	    <html>
	      <head>
				  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
	        <title>ReactNative</title>
					
					<link href="toc/style/github-bf51422f4bb36427d391e4b75a1daa083c2d840e.css" media="all" rel="stylesheet" type="text/css"/>
					<link href="toc/style/github2-d731afd4f624c99a4b19ad69f3083cd6d02b81d5.css" media="all" rel="stylesheet" type="text/css"/>
					<link href="toc/css/zTreeStyle/zTreeStyle.css" media="all" rel="stylesheet" type="text/css"/>
			
				  <style>
					pre {
					    counter-reset: line-numbering;
					    border: solid 1px #d9d9d9;
					    border-radius: 0;
					    background: #fff;
					    padding: 0;
					    line-height: 23px;
					    margin-bottom: 30px;
					    white-space: pre;
					    overflow-x: auto;
					    word-break: inherit;
					    word-wrap: inherit;
					}

					pre a::before {
					  content: counter(line-numbering);
					  counter-increment: line-numbering;
					  padding-right: 1em; /* space after numbers */
					  width: 25px;
					  text-align: right;
					  opacity: 0.7;
					  display: inline-block;
					  color: #aaa;
					  background: #eee;
					  margin-right: 16px;
					  padding: 2px 10px;
					  font-size: 13px;
					  -webkit-touch-callout: none;
					  -webkit-user-select: none;
					  -khtml-user-select: none;
					  -moz-user-select: none;
					  -ms-user-select: none;
					  user-select: none;
					}

					pre a:first-of-type::before {
					  padding-top: 10px;
					}

					pre a:last-of-type::before {
					  padding-bottom: 10px;
					}

					pre a:only-of-type::before {
					  padding: 10px;
					}
			
					.highlight { background-color: #ffffcc } /* RIGHT */
					</style>
	      </head>
	      <body>
				  <div>
							<div style='width:25%;'>
									<ul id="tree" class="ztree" style='width:100%'>
		
									</ul>
							</div>
			        <div id='readme' style='width:70%;margin-left:20%;'>
			          	<article class='markdown-body'>
			            	<style>.highlight .hll { background-color: #ffffcc }
.highlight  { background: #f0f0f0; }
.highlight .c { color: #60a0b0; font-style: italic } /* Comment */
.highlight .err { border: 1px solid #FF0000 } /* Error */
.highlight .k { color: #007020; font-weight: bold } /* Keyword */
.highlight .o { color: #666666 } /* Operator */
.highlight .ch { color: #60a0b0; font-style: italic } /* Comment.Hashbang */
.highlight .cm { color: #60a0b0; font-style: italic } /* Comment.Multiline */
.highlight .cp { color: #007020 } /* Comment.Preproc */
.highlight .cpf { color: #60a0b0; font-style: italic } /* Comment.PreprocFile */
.highlight .c1 { color: #60a0b0; font-style: italic } /* Comment.Single */
.highlight .cs { color: #60a0b0; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #A00000 } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gr { color: #FF0000 } /* Generic.Error */
.highlight .gh { color: #000080; font-weight: bold } /* Generic.Heading */
.highlight .gi { color: #00A000 } /* Generic.Inserted */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #c65d09; font-weight: bold } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #800080; font-weight: bold } /* Generic.Subheading */
.highlight .gt { color: #0044DD } /* Generic.Traceback */
.highlight .kc { color: #007020; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #007020; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #007020; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #007020 } /* Keyword.Pseudo */
.highlight .kr { color: #007020; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #902000 } /* Keyword.Type */
.highlight .m { color: #40a070 } /* Literal.Number */
.highlight .s { color: #4070a0 } /* Literal.String */
.highlight .na { color: #4070a0 } /* Name.Attribute */
.highlight .nb { color: #007020 } /* Name.Builtin */
.highlight .nc { color: #0e84b5; font-weight: bold } /* Name.Class */
.highlight .no { color: #60add5 } /* Name.Constant */
.highlight .nd { color: #555555; font-weight: bold } /* Name.Decorator */
.highlight .ni { color: #d55537; font-weight: bold } /* Name.Entity */
.highlight .ne { color: #007020 } /* Name.Exception */
.highlight .nf { color: #06287e } /* Name.Function */
.highlight .nl { color: #002070; font-weight: bold } /* Name.Label */
.highlight .nn { color: #0e84b5; font-weight: bold } /* Name.Namespace */
.highlight .nt { color: #062873; font-weight: bold } /* Name.Tag */
.highlight .nv { color: #bb60d5 } /* Name.Variable */
.highlight .ow { color: #007020; font-weight: bold } /* Operator.Word */
.highlight .w { color: #bbbbbb } /* Text.Whitespace */
.highlight .mb { color: #40a070 } /* Literal.Number.Bin */
.highlight .mf { color: #40a070 } /* Literal.Number.Float */
.highlight .mh { color: #40a070 } /* Literal.Number.Hex */
.highlight .mi { color: #40a070 } /* Literal.Number.Integer */
.highlight .mo { color: #40a070 } /* Literal.Number.Oct */
.highlight .sa { color: #4070a0 } /* Literal.String.Affix */
.highlight .sb { color: #4070a0 } /* Literal.String.Backtick */
.highlight .sc { color: #4070a0 } /* Literal.String.Char */
.highlight .dl { color: #4070a0 } /* Literal.String.Delimiter */
.highlight .sd { color: #4070a0; font-style: italic } /* Literal.String.Doc */
.highlight .s2 { color: #4070a0 } /* Literal.String.Double */
.highlight .se { color: #4070a0; font-weight: bold } /* Literal.String.Escape */
.highlight .sh { color: #4070a0 } /* Literal.String.Heredoc */
.highlight .si { color: #70a0d0; font-style: italic } /* Literal.String.Interpol */
.highlight .sx { color: #c65d09 } /* Literal.String.Other */
.highlight .sr { color: #235388 } /* Literal.String.Regex */
.highlight .s1 { color: #4070a0 } /* Literal.String.Single */
.highlight .ss { color: #517918 } /* Literal.String.Symbol */
.highlight .bp { color: #007020 } /* Name.Builtin.Pseudo */
.highlight .fm { color: #06287e } /* Name.Function.Magic */
.highlight .vc { color: #bb60d5 } /* Name.Variable.Class */
.highlight .vg { color: #bb60d5 } /* Name.Variable.Global */
.highlight .vi { color: #bb60d5 } /* Name.Variable.Instance */
.highlight .vm { color: #bb60d5 } /* Name.Variable.Magic */
.highlight .il { color: #40a070 } /* Literal.Number.Integer.Long */</style>
<p><center><font size=6><strong>React Native 编码规范</strong></font></center></p>

<h2>基本规范</h2>

<blockquote>
<p>1.每个文件只包含一个React组件，命名要顾名知义</p>

<p>2.尽可能的使用ES6语法</p>

<p>3.console，alert在调试时写，调试完立即删除</p>

<p>4.代码缩进格式统一，工具类方法注意添加注释</p>
</blockquote>

<h2>命名规范</h2>

<blockquote>
<p>1.命名中不要出现中文</p>

<p>2.文件名: 文件夹和文件名要使用大驼峰命名法,比如 HomeIndex.js</p>

<p>3.图片命名规则： 模块_xx.png 或者 模块/xx.png</p>
</blockquote>
<div class="highlight"><pre><span></span>  setting_bg.png
  setting/bg.png
</pre></div>
<blockquote>
<p>4 组件命名: 与文件名（除中缀外）完全一致。如果组件单独放置在目录中，则目录名也一致。</p>
</blockquote>
<div class="highlight"><pre><span></span>  <span class="kn">import</span> <span class="nn">FootView</span> <span class="nn">from</span> <span class="s1">&#39;./FootView&#39;</span>
</pre></div>
<h2>变量与常量声明</h2>

<h3>变量</h3>

<blockquote>
<p>1.尽量使用let来代替var</p>

<p>2.对于全局变量声明，采用<code>global.xxx = xxx</code>，但应避免声明过多全局变量污染环境</p>
</blockquote>

<h3>常量</h3>

<blockquote>
<p>1.对于常量应使用const进行声明，命名采用驼峰写法</p>

<p>2.对于使用 immutable(不可改变的) 数据应用const进行声明</p>
</blockquote>

<h3>字符串</h3>

<blockquote>
<p>1.以反引号( ` )标示</p>

<p>2.可读性更强，代码更易编写</p>
</blockquote>
<div class="highlight"><pre><span></span>   `How are you, <span class="cp">${</span><span class="n">name</span><span class="cp">}</span>?`
</pre></div>
<h2>属性</h2>

<h3>属性名</h3>

<blockquote>
<p>1.组件的属性使用小驼峰命名法</p>
</blockquote>
<div class="highlight"><pre><span></span>  fontSize={12}, textColor=&#39;#FFFFFF&#39; 
</pre></div>
<blockquote>
<p>2.使用外联样式时,属性名最好带有Style关键字</p>
</blockquote>
<div class="highlight"><pre><span></span>  flexStyle.js
</pre></div>
<h3>属性设置</h3>

<blockquote>
<p>1.在封装的组件内最好设置属性(以便<code>propTypes</code>校验),以免类型不对导致的错误。</p>

<p>2.属性较多使用<code>{...this.props}</code>语法(最好在属性开头加上<code>{...this.props}</code>,为了防止少写属性,产生报错)</p>
</blockquote>

<h2>注释</h2>

<blockquote>
<p>1.组件之间的注释需要用 <code>{/* 注释内容 */}</code> 包裹 </p>
</blockquote>
<div class="highlight"><pre><span></span>    {/* 这是组件间注释 */}
</pre></div>
<blockquote>
<p>2.组件之外的注释使用 <code>{/* 注释内容 */}</code> 或者 <code>// 注释内容</code></p>
</blockquote>
<div class="highlight"><pre><span></span> {/* 这是组件间注释 */}
 // 这是组件外注释 
</pre></div>
<h2>条件输入</h2>

<blockquote>
<p>1.条件输出值 </p>
</blockquote>
<div class="highlight"><pre><span></span>  {this.state.on ? &#39;On&#39; : &#39;Off&#39;}
</pre></div>
<blockquote>
<p>2.条件输出组件内容 </p>
</blockquote>
<div class="highlight"><pre><span></span>  {this.state.on ? <span class="nt">&lt;Text&gt;</span>On<span class="nt">&lt;/Text&gt;</span> : <span class="nt">&lt;Text&gt;</span>Off<span class="nt">&lt;/Text&gt;</span>}
</pre></div>
<h2>组件</h2>

<blockquote>
<p>使用class与extends关键字。不使用React.createClass方法。需要导出的组件直接在class关键字前使用export default。</p>
</blockquote>
<div class="highlight"><pre><span></span><span class="c1">// bad</span>
<span class="kr">export</span> <span class="k">default</span> <span class="nx">React</span><span class="p">.</span><span class="nx">createClass</span><span class="p">({</span>
<span class="p">});</span>

<span class="c1">// good</span>
<span class="kr">export</span> <span class="k">default</span> <span class="kr">class</span> <span class="nx">HomeView</span> <span class="kr">extends</span> <span class="nx">Component</span> <span class="p">{</span>
<span class="p">}</span>

<span class="kr">class</span> <span class="nx">HomeView</span> <span class="kr">extends</span> <span class="nx">Component</span> <span class="p">{</span>
<span class="p">}</span>
<span class="kr">export</span> <span class="k">default</span>
</pre></div>
<h3>自闭合标签</h3>

<blockquote>
<p>1.JSX 中所有标签必须闭合, 没有子元素的组件使用自闭合语法，自闭合标签 / 前留一个空格；</p>
</blockquote>

<p>example:</p>
<div class="highlight"><pre><span></span>// bad
<span class="nt">&lt;Logo&gt;&lt;/Logo&gt;</span>
<span class="nt">&lt;Logo</span>    <span class="nt">/&gt;</span>
<span class="nt">&lt;Logo</span>
 <span class="nt">/&gt;</span>
// good
<span class="nt">&lt;Logo</span> <span class="nt">/&gt;</span>
</pre></div>
<h3>state/props</h3>

<blockquote>
<p>对于多个单词组成的pros，使用驼峰命名法。不使用下划线或连接线。</p>
</blockquote>
<div class="highlight"><pre><span></span>// bad
var userName = this.props.userName;
let checked = this.state.checked;

// good
const { userName, age, sex } = this.props;
const { checked } = this.state;
</pre></div>
<h3>括号</h3>

<blockquote>
<p>当JSX标签超过一行时，使用括号包裹。单行时，不必有括号。</p>
</blockquote>
<div class="highlight"><pre><span></span>/// bad
render() {
  return <span class="nt">&lt;View&gt;</span>
           <span class="nt">&lt;Image</span> <span class="nt">/&gt;</span>
         <span class="nt">&lt;/View&gt;</span>;
}

// good
render() {
  return (
    <span class="nt">&lt;View&gt;</span>
      <span class="nt">&lt;Image</span> <span class="nt">/&gt;</span>
    <span class="nt">&lt;/View&gt;</span>
  );
}

// good, when single line
render() {
  return <span class="nt">&lt;Text&gt;</span>{body}<span class="nt">&lt;/Text&gt;</span>;
</pre></div>
<h3>方法声明的顺序</h3>

<blockquote>
<p>原则上按如下顺序排列React组件的各个方法（生命周期）：</p>
</blockquote>
<div class="highlight"><pre><span></span>1. constructor
2. 静态方法（static methods)
3. getChildContext
4. componentWillMount
5. componentDidMount
6. componentWillReceiveProps
7. shouldComponentUpdate
8. componentWillUpdate
9. componentDidUpdate
10. componentWillUnmount
11. 点击处理或事件处理函数，比如onClickSubmit()、 onChangeDescription()
12. 用在render中的getter方法，比如getSelectReason()、 getFooterContent()
13. 可选的render方法，比如renderNavigation()、renderProfilePicture()
14. render
</pre></div>
<p>或者</p>
<div class="highlight"><pre><span></span>1. constructor
2. 静态方法（static methods)
3. getChildContext
4. componentWillMount
5. componentDidMount
6. componentWillReceiveProps
7. shouldComponentUpdate
8. componentWillUpdate
9. componentDidUpdate
10. componentWillUnmount
11. 点击处理或事件处理函数，比如onClickSubmit()、 onChangeDescription()
12. 用在render中的getter方法，比如getSelectReason()、 getFooterContent()
13. render
14. 抽离的组件代码块，例如renderItemView，renderHeaderView
</pre></div>
<h2>模块</h2>

<blockquote>
<p>1.使用import / export来做模块加载导出，不使用非标准模块写法</p>
</blockquote>
<div class="highlight"><pre><span></span><span class="o">//</span> <span class="err">不好</span>
<span class="n">const</span> <span class="n">colors</span>  <span class="o">=</span> <span class="n">require</span><span class="p">(</span><span class="s1">&#39;./colors&#39;</span><span class="p">);</span>
<span class="n">module</span><span class="o">.</span><span class="n">exports</span> <span class="o">=</span> <span class="n">color</span><span class="o">.</span><span class="n">lightRed</span><span class="p">;</span>

<span class="o">//</span> <span class="err">好</span>
<span class="kn">import</span> <span class="p">{</span> <span class="n">lightRed</span> <span class="p">}</span> <span class="kn">from</span> <span class="s1">&#39;./colors&#39;</span><span class="p">;</span>
<span class="n">export</span> <span class="n">default</span> <span class="n">lightRed</span><span class="p">;</span>
</pre></div>
<blockquote>
<p>2.import / export 后面采用花括号{ }引入模块的写法时，须在花括号内左右各保留一个空格</p>
</blockquote>
<div class="highlight"><pre><span></span><span class="o">//</span> <span class="err">不好</span>
<span class="kn">import</span> <span class="p">{</span><span class="n">lightRed</span><span class="p">}</span> <span class="kn">from</span> <span class="s1">&#39;./colors&#39;</span><span class="p">;</span>
<span class="kn">import</span> <span class="p">{</span> <span class="n">lightRed</span><span class="p">}</span> <span class="kn">from</span> <span class="s1">&#39;./colors&#39;</span><span class="p">;</span>
<span class="o">//</span> <span class="err">好</span>
<span class="kn">import</span> <span class="p">{</span> <span class="n">lightRed</span> <span class="p">}</span> <span class="kn">from</span> <span class="s1">&#39;./colors&#39;</span><span class="p">;</span>
</pre></div>
<h1>箭头函数书写约定</h1>

<blockquote>
<p>1.函数体只有单行语句时，允许写在同一行并去除花括号</p>

<p>2.当函数只有一个参数时，允许去除参数外层的括号</p>
</blockquote>
<div class="highlight"><pre><span></span>// 好
const foo = x =&gt; x + x; // 注意此处会隐性return x + x
const foo = (x) =&gt; {
  return x + x; // 若函数体有花括号语句块时须进行显性的return
}; 
[1, 2, 3].map( x =&gt; x * x);

// 不好
(function(){
    console.log(&#39;哈&#39;);
})();

// 好
(()=&gt;{
    console.log(&#39;哈&#39;);
})();
</pre></div>
			          	</article>
			        </div>
					</div>
	      </body>
	    </html>
			<script type="text/javascript" src="toc/js/jquery-1.4.4.min.js"></script>
			<script type="text/javascript" src="toc/js/jquery.ztree.all-3.5.min.js"></script>
			<script type="text/javascript" src="toc/js/ztree_toc.js"></script>
			<SCRIPT type="text/javascript" >
			<!--
			$(document).ready(function(){
				$('#tree').ztree_toc({
					is_auto_number:true,
					documment_selector:'.markdown-body'
				});
			});
			//-->
			</SCRIPT>
	  